package ps.client.gui.dialog.trigger;

import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import ps.client.gui.util.DialogEx;


@SuppressWarnings("serial")
public class MoveToCategoryDialog extends DialogEx {
    
    private JPanel contentPanel = new JPanel(new BorderLayout(10, 20));
    private JLabel categoryLabel = new JLabel("Verschieben nach: ");
    private JComboBox categoryComboBox = new JComboBox();
    
    private JPanel outerButtonPanel = new JPanel(new BorderLayout());
    private JPanel innerButtonPanel = new JPanel(new GridLayout(1, 2, 5, 0));
    private JButton okButton = new JButton("Ok");
    private JButton cancelButton = new JButton("Abbrechen");
    
    public MoveToCategoryDialog(Dialog owner, String prefNode) {
        super(owner, prefNode);
        
        setTitle("Nach Kategorie verschieben");
        setMinimumSize(new Dimension(300, 0));
        setResizable(false);
        setModal(true);
        
        getContentPane().add(contentPanel);
        contentPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
        contentPanel.add(categoryLabel, BorderLayout.WEST);
        contentPanel.add(categoryComboBox, BorderLayout.CENTER);
        contentPanel.add(outerButtonPanel, BorderLayout.SOUTH);
        
        outerButtonPanel.add(innerButtonPanel, BorderLayout.EAST);
        innerButtonPanel.add(okButton);
        innerButtonPanel.add(cancelButton);
        
        pack();
        
        okButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                setVisible(false);
                String category = null;
                if (categoryComboBox.getSelectedItem() != null) {
                    category = (String)categoryComboBox.getSelectedItem();
                }
                fireOk(category);
            }
        });
        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                setVisible(false);
            }
        });
    }
    
    public void setCategories(String[] categories) {
        categoryComboBox.removeAllItems();
        for (String category : categories) {
            categoryComboBox.addItem(category);
        }
        pack();
    }
    
    protected void fireOk(String category) {
    }

}
